# -*- coding: utf-8 -*-
"""
@Time   :  "2024/8/7 22:36"
@Author :  Dilee
"""
from dataclasses import dataclass

from flask import Flask, Blueprint
from injector import inject

from internal.handler import AppHandler


@inject
@dataclass
class Router:
    """路由"""
    app_handler: AppHandler

    def __init__(self, app_handler: AppHandler):
        self.app_handler = app_handler

    def register_router(self, app: Flask):
        """注册路由"""
        # 1.创建一个蓝图
        bp = Blueprint('llmops', __name__, url_prefix="")

        # 2.将url与视图函数关联
        bp.add_url_rule('/ping', view_func=self.app_handler.ping)
        bp.add_url_rule('/app/completion', view_func=self.app_handler.completion, methods=['POST'])
        bp.add_url_rule('/app', view_func=self.app_handler.create_app, methods=['POST'])
        bp.add_url_rule('/app/<aid>', view_func=self.app_handler.get_app, methods=['GET'])
        bp.add_url_rule('/app/<aid>', view_func=self.app_handler.update_app, methods=['POST'])
        bp.add_url_rule('/app/<aid>/delete', view_func=self.app_handler.delete_app, methods=['POST'])
        # 3.将蓝图注册到app
        app.register_blueprint(bp)
